const clickhouse = require('../config/ch')
class publicModel {
  // 创建账单（插入）
  static async create (query) {
    const insert = async () => await clickhouse.query(query).toPromise()
    try {
      return await insert()
    } catch (error) {
      console.error('Error creating article:', error)
      throw error
    }
  }
  // 查询单条记录
  static async getOne (query) {
    try {
      const result = await clickhouse.query(query).toPromise();
      // ClickHouse 查询返回数组，这里取第一条
      return result && result.length > 0 ? result[0] : null;
    } catch (error) {
      console.error('Error in getOne:', error);
      throw error;
    }
  }
  // 查询所有列表
  static async getList (query) {
    const result = await clickhouse.query(query).toPromise()
    try {
      return result
    } catch {
      throw error
    }
  }
}

module.exports = publicModel
